styleproperty: Save some memory
authorBenjamin Otte <otte@redhat.com>
Sat, 7 Apr 2012 19:32:39 +0000 (21:32 +0200)
committerBenjamin Otte <otte@redhat.com>
Mon, 9 Apr 2012 01:14:51 +0000 (03:14 +0200)
Only create a new CssValue when we actually need one.

gtk/gtkcssstylepropertyimpl.c

index 7dd1cf40b83b85af72655b53a0fce9f38114c623..0528ae05cbcf0b7b0b897e64012333c1600187d4 100644 (file)
@@ -400,10 +400,20 @@ css_image_value_compute (GtkCssStyleProperty    *property,
                          GtkStyleContext        *context,
                          GtkCssValue            *specified)
 {
-  GtkCssImage *image = _gtk_css_value_get_image (specified);
+  GtkCssImage *image, *computed;
+  
+  image = _gtk_css_value_get_image (specified);
 
-  if (image)
-    image = _gtk_css_image_compute (image, context);
+  if (image == NULL)
+    return _gtk_css_value_ref (specified);
+
+  computed = _gtk_css_image_compute (image, context);
+
+  if (computed == image)
+    {
+      g_object_unref (computed);
+      return _gtk_css_value_ref (specified);
+    }
 
   return _gtk_css_value_new_take_image (image);
 }